package com.link2room.optimus.controller.manager;

import com.link2room.common.constant.BaseConstant;
import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.common.jpa.result.QueryResult;
import com.link2room.optimus.dto.param.manager.L2RRateplanManagerParamDto;
import com.link2room.optimus.dto.result.base.L2RRateplanDto;
import com.link2room.optimus.facade.IL2RRateplanFacadeService;
import com.link2room.sideswipe.permissionResouces.annotation.L2RPermissionResources;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import static com.link2room.optimus.constant.PermissionConstant.*;

/**
 * Created by sss on 2016/8/29.
 */
@Api(tags = "联房价格计划管理")
@RestController
@RequestMapping("/manager/L2RRateplans")
public class L2RRateplanManagerController {
    @Resource
    private IL2RRateplanFacadeService l2rRateplanFacadeService;

    @ApiOperation(value = "获取联房价格计划列表",response = L2RRateplanDto.class)
    @RequestMapping(method = RequestMethod.GET)
    @L2RPermissionResources(value = L2RRateplans, name = "价格计划列表")
    public BaseResultDto l2RRateplans(
            @RequestParam(value = "mcCode", required = true) String mcCode
    ) throws Exception {
        L2RRateplanManagerParamDto l2RRateplanManagerParamDto = new L2RRateplanManagerParamDto();
        l2RRateplanManagerParamDto.setMcCode(mcCode);
        QueryResult<L2RRateplanDto> l2rRateplanDtoResult = l2rRateplanFacadeService.listL2RRateplans(l2RRateplanManagerParamDto);
        BaseResultDto l2rRs = new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setQueryResult(l2rRateplanDtoResult);
        return l2rRs;
    }

    @ApiOperation(value = "根据ID获取联房价格计划",response = L2RRateplanDto.class)
    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    @L2RPermissionResources(value = L2RRateplanById, name = "价格计划详情ById")
    public BaseResultDto l2RRateplan(
            @PathVariable Long id
    ) throws Exception {
        L2RRateplanManagerParamDto l2RRateplanManagerParamDto = new L2RRateplanManagerParamDto();
        l2RRateplanManagerParamDto.setId(id);
        L2RRateplanDto l2rRateplanDto = l2rRateplanFacadeService.getL2RRateplanById(l2RRateplanManagerParamDto);
        BaseResultDto l2rRs = new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(l2rRateplanDto);
        return l2rRs;
    }

    @ApiOperation(value = "根据rpCode获取联房价格计划",response = L2RRateplanDto.class)
    @RequestMapping(value = "/L2RRateplan",method = RequestMethod.GET)
    @L2RPermissionResources(value = L2RRateplan, name = "价格计划详情")
    public BaseResultDto l2RRateplan(
            @RequestParam(value = "rpCode", required = true) String rpCode
    ) throws Exception {
        L2RRateplanManagerParamDto l2RRateplanManagerParamDto =new L2RRateplanManagerParamDto();
        l2RRateplanManagerParamDto.setRpCode(rpCode);
        L2RRateplanDto l2rRateplanDto = l2rRateplanFacadeService.getL2RRateplanByRpcode(l2RRateplanManagerParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(l2rRateplanDto);
        return l2rRs;
    }

    @ApiOperation(value = "新建联房价格计划")
    @RequestMapping(method = RequestMethod.POST)
    @L2RPermissionResources(value = newL2RRateplan, name = "新建价格计划")
    public BaseResultDto newL2RRateplan(
            @RequestBody L2RRateplanManagerParamDto l2RRateplanManagerParamDto
    ) throws Exception {
        L2RRateplanDto l2RRateplanDto=l2rRateplanFacadeService.saveL2RRateplan(l2RRateplanManagerParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultMessage(BaseConstant.BaseMessageConstant.SAVESUCCESS);
        l2rRs.setResultInfo(l2RRateplanDto);
        return l2rRs;
    }

    @ApiOperation(value = "更新联房价格计划")
    @RequestMapping(method = RequestMethod.PUT)
    @L2RPermissionResources(value = updateL2RRateplan, name = "更新价格计划")
    public BaseResultDto basePriceStaticsModify(
            @RequestBody L2RRateplanManagerParamDto l2RRateplanManagerParamDto
    ) throws Exception {
        L2RRateplanDto l2RRateplanDto=l2rRateplanFacadeService.updateL2RRateplan(l2RRateplanManagerParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultMessage(BaseConstant.BaseMessageConstant.UPDATESUCCESS);
        l2rRs.setResultInfo(l2RRateplanDto);
        return l2rRs;
    }
}
